package com.rn.ddd.interfaces.facade;

import com.rn.ddd.application.service.OrderAppService;
import com.rn.ddd.interfaces.assembler.OrderAssembler;
import com.rn.ddd.interfaces.dto.OrderCreateQuery;
import com.rn.gypsophila.model.GlobalRet;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "订单-API")
@RestController
@RequestMapping("/ddd/api/order")
public class OrderController {

    @Autowired
    private OrderAppService orderAppService;

    @ApiOperation("创建订单")
    @PostMapping
    public GlobalRet<Long> createOrder(@Valid @RequestBody OrderCreateQuery createQuery) {
        return GlobalRet.success(orderAppService.createOrder(OrderAssembler.toEntity(createQuery)));
    }


}
